package com.dullwolf.utils;

import com.jfinal.kit.StrKit;

import java.util.Properties;
import java.util.regex.Pattern;


public class StringUtil {


	/**
	 * 每隔三个数字加一个逗号
	 * @param str1 数字
	 * @return
	 */
	public static String fen(String str1){
		str1 = new StringBuilder(str1).reverse().toString();//先将字符串颠倒顺序
		String str2 = "";
		for(int i=0;i<str1.length();i++){
			if(i*3+3>str1.length()){
				str2 += str1.substring(i*3, str1.length());
				break;
			}
			str2 += str1.substring(i*3, i*3+3)+",";
		}
		if(str2.endsWith(",")){
			str2 = str2.substring(0, str2.length()-1);
		}
		//最后再将顺序反转过来
		return new StringBuilder(str2).reverse().toString();
	}

	/**
	 * 移除多余空行和空格
	 */
	public static String delRedundantBlankLine(String content) {
		content = content.replaceAll("\\r", "\n").replaceAll(" {2,}", " ");
		String[] split = content.split("\\n");
		StringBuilder sb = new StringBuilder();
		for (String s:split) {
			if(StrKit.notBlank(s.trim())){
				sb.append(s.trim()).append("\n");
			}
		}
		sb.delete(sb.length()-1,sb.length());
		return sb.toString();
	}


	public static boolean extractHttpMessage(String msg){
		if(StrKit.notBlank(msg)){
			if(msg.contains("https://gchat.qpic.cn")){
				msg = msg.replace("https://gchat.qpic.cn", "");
			}
			return msg.contains("http");
		}
		return false;
	}

}
